package ch.ethz.fcl.metrobuzz.controller.gui.twl.frames;

import ch.ethz.fcl.metrobuzz.controller.MBController;
import de.matthiasmann.twl.Color;
import de.matthiasmann.twl.DialogLayout;
import de.matthiasmann.twl.ResizableFrame;
import de.matthiasmann.twl.utils.TintAnimator;

public abstract class MBFrame extends ResizableFrame {
	protected MBController control;
	protected String title;
	protected DialogLayout layout;

	protected void create(MBController control, String title) {
		this.control = control;
		this.title = title;
		init();
	}

	protected void init() {
		this.setDraggable(false);
		this.setTheme("mbdialog");
		this.setTitle(title);

		layout = new DialogLayout();
		layout.setTheme("settings");

		setLayout();

		this.add(layout);
		layout.adjustSize();
	}

	protected abstract void setLayout();

	@Override
	public void setVisible(boolean visible) {
		if (visible) {
			TintAnimator tintAnimator = getTintAnimator();
			if ((tintAnimator != null && tintAnimator.hasTint())
					|| !super.isVisible()) {
				fadeTo(Color.WHITE, super.getFadeDurationShow());
			}
		} else if (super.isVisible()) {
			fadeToHide(super.getFadeDurationHide());
		}
	}

	public MBController getControl() {
		return control;
	}
}
